//
//  OrderListFootTableViewHeaderFooterView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/26.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OrderListFootTableViewHeaderFooterView.h"

@implementation OrderListFootTableViewHeaderFooterView
{
    NSMutableArray *btnArr;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        GLGWView * bankGroundView = [[GLGWView alloc] initWithInSuperView:self.contentView];
        [bankGroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView).offset(0);
        }];
        btnArr = [NSMutableArray array];
        CGFloat butWidth = KScreenWidth - kWidthProportion_In_iPhoneTriploid(75)*4 -kWidthProportion_In_iPhoneTriploid(45);
        for (int i=0; i<4; i++) {
            GLGWButton * bottomBut = [[GLGWButton alloc] initWithFrame:CGRectMake(butWidth+kWidthProportion_In_iPhoneTriploid(75)*i+kWidthProportion_In_iPhoneTriploid(10)*i, kHeightProportion_In_iPhoneTriploid(15), kWidthProportion_In_iPhoneTriploid(75), kHeightProportion_In_iPhoneTriploid(30)) hTitle:@"哈哈" titleLableFont:SYSTEMFONT(12) titleLableColor:[UIColor colorWithHexString:@"#666666"] theCornerRadius:kHeightProportion_In_iPhoneTriploid(15) theBorderWidth:1.0 theBorderColor:kColor_Rule_Yellow backgroundColr:[UIColor whiteColor] inSuperView:self];
            [bottomBut addTarget:self action:@selector(bottomButAction:) forControlEvents:UIControlEventTouchUpInside];
            [btnArr addObject:bottomBut];
        }
    }
    return self;
}

- (void)bottomButAction:(GLGWButton *)sender {
    if (self.Block_BottomAction) {
        self.Block_BottomAction(sender, self.section);
    }
}

- (void)setDetailListModel:(AllOrderDetailListModel *)detailListModel
{
    _detailListModel = detailListModel;
    // 1：确认中(卖家：待您确认，买家/自由经理人：卖家确认中)2：待支付；3：线下支付待确认；4：待商家发货；5：待收货；6：交易完成；18：支付超时；19：订单取消
    NSInteger cout = 340;
    
    for (int i = 0; i < btnArr.count; i ++) {
        GLGWButton *btn = btnArr[i];
        btn.tag = cout;
        
        switch (detailListModel.orderStatus) {
            case 1: 
                if (i == 0) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                } else if (i == 3) {
                    [self btnStatus:btn titleStr:@"取消并撤回" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 2];
                }
                break;
            case 2: // 这个是放在另外一个cell中的
                if (i == 0) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"取消订单" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 3];
                } else if (i == 3) {
                    [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 4];
                }
                break;
            case 3:
                if (i == 0) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 3) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                }
                break;
            case 4:
                if (i == 0) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                } else if (i == 3) {
                    [self btnStatus:btn titleStr:@"取消并撤回" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 2];
                }
                break;
            case 5: // 这个需要判断是否有提货单
                if (detailListModel.receivingGoodsType == 1) {
                    if (i == 0) {
                        btn.hidden = YES;
                    } else if (i == 1) {
                        [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                    } else if (i == 2) {
                        [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                    } else if (i == 3) {
                        [self btnStatus:btn titleStr:@"确认收货" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 5];
                    }
                } else {
                    if (i == 0) { // 这里是有提货单的
                        [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                    } else if (i == 1) {
                        [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                    } else if (i == 2) {
                        [self btnStatus:btn titleStr:@"提货单" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 6];
                    } else if (i == 3) {
                        [self btnStatus:btn titleStr:@"确认收货" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 5];
                    }
                }
                break;
            case 6:
                if (i == 0) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"申请发票" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 7];
                } else if (i == 3) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                }
                break;
            case 18:
                break;
            case 19:
                if (i == 0) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    btn.hidden = YES;
                } else if (i == 3) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                }
                break;
            default:
                break;
        } 
    }
}

- (void)btnStatus:(GLGWButton *)btn titleStr:(NSString *)titleStr textColor:(NSString *)colorStr layerColor:(NSString *)layerColorStr tag:(NSInteger)tag
{
    [btn setTitle:titleStr forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:colorStr] forState:UIControlStateNormal];
    btn.layer.borderColor = [UIColor colorWithHexString:layerColorStr].CGColor;
    btn.tag = tag;
    btn.hidden = NO;
}

@end
